//
//  BaseViewController.swift
//  WeiBo_Private
//
//  Created by Yangperlove on 16/1/10.
//  Copyright © 2016年 Yangperlove. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {
    
    var userLogin = UserAccountViewModel().isUserLogin()
    var visitor: VisitorView?
    
    //loadView
    //1. -苹果专门为 手写代码准备的 一旦实现该方法 sb / xib 会自动失效
    //2. 准备视图层次结构 在UIViewController 中 会将view 准备出来
    //3.在super.loadView之前 view没有被创建出来(nil) 追踪view 会造成递归调用
    override func loadView() {
        
        if userLogin {
            super.loadView()
        } else {
            visitor = VisitorView()
            visitor?.visitorDegate = self
            view = visitor

            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "userWillLogin")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
            
            NSNotificationCenter.defaultCenter().postNotificationName(HidenPlusBtn, object: nil)
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
}

//遵守协议
extension BaseViewController: VisitorDegate {
    func userWillLogin() {
        let oAuth = OAuthViewController()
        let nav = UINavigationController(rootViewController: oAuth)
        presentViewController(nav, animated: true, completion: nil)
    }
    func userWillRegister() {
        
    }
}
